/*    */ package com.wgcloud.common;
/*    */ 
/*    */ import cn.hutool.core.collection.CollectionUtil;
/*    */ import cn.hutool.json.JSONArray;
/*    */ import cn.hutool.json.JSONObject;
/*    */ import cn.hutool.json.JSONUtil;
/*    */ import com.wgcloud.common.NettyServer;
/*    */ import com.wgcloud.config.CommonConfig;
/*    */ import com.wgcloud.dto.HostWarnDiyDto;
/*    */ import com.wgcloud.util.staticvar.StaticKeys;
/*    */ import java.io.File;
/*    */ import java.nio.charset.Charset;
/*    */ import java.util.Collection;
/*    */ import javax.servlet.ServletContext;
/*    */ import org.apache.commons.lang3.StringUtils;
/*    */ import org.slf4j.Logger;
/*    */ import org.slf4j.LoggerFactory;
/*    */ import org.springframework.beans.factory.annotation.Autowired;
/*    */ import org.springframework.boot.ApplicationArguments;
/*    */ import org.springframework.boot.ApplicationRunner;
/*    */ import org.springframework.stereotype.Component;
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ @Component
/*    */ public class ApplicationStartListener
/*    */   implements ApplicationRunner
/*    */ {
/* 32 */   private Logger logger = LoggerFactory.getLogger(com.wgcloud.common.ApplicationStartListener.class);
/*    */   
/*    */   @Autowired
/*    */   CommonConfig commonConfig;
/*    */   
/*    */   @Autowired
/*    */   private ServletContext servletContext;
/*    */   
/*    */   public void run(ApplicationArguments args) throws Exception {
/* 41 */     this.servletContext.setAttribute("sidebarCollapse", this.commonConfig.getSidebarCollapse());
/*    */     
/*    */     try {
/* 44 */       String path = System.getProperty("user.dir");
/* 45 */       File file = new File(path + "/config/hostWarnDiy.json");
/* 46 */       if (file.exists()) {
/* 47 */         this.logger.info("发现并解析hostWarnDiy.json");
/* 48 */         JSONArray hostJsonArray = JSONUtil.readJSONArray(file, Charset.forName("utf-8"));
/* 49 */         if (!CollectionUtil.isEmpty((Collection)hostJsonArray)) {
/* 50 */           for (int i = 0; i < hostJsonArray.size(); i++) {
/* 51 */             JSONObject jsonObject = JSONUtil.parseObj(hostJsonArray.get(i));
/* 52 */             HostWarnDiyDto hostWarnDto = (HostWarnDiyDto)JSONUtil.toBean(jsonObject, HostWarnDiyDto.class);
/* 53 */             if (!StringUtils.isEmpty(hostWarnDto.getHostname()))
/*    */             {
/*    */               
/* 56 */               StaticKeys.HOST_WARN_MAP.put(hostWarnDto.getHostname(), hostWarnDto);
/*    */             }
/*    */           } 
/*    */         }
/*    */       } 
/* 61 */     } catch (Exception e) {
/* 62 */       this.logger.error("hostWarnDiy.json解析错误：", e);
/*    */     } 
/*    */     
/*    */     try {
/* 66 */       this.servletContext.setAttribute("webSsh", this.commonConfig.getWebSsh());
/* 67 */       if ("true".equals(this.commonConfig.getWebSsh())) {
/* 68 */         this.logger.info("NettyServer服务启动，端口：" + this.commonConfig.getWebSshPort());
/* 69 */         NettyServer.start(this.commonConfig.getWebSshPort().intValue());
/*    */       } 
/* 71 */     } catch (Exception e) {
/* 72 */       this.logger.error("NettyServer服务启动错误：", e);
/*    */     } 
/*    */   }
/*    */ }


/* Location:              /Users/zhangyongxin/soft-install/wgcloud/wgcloud-v3.3.5/server/bank/wgcloud-server-release.jar!/BOOT-INF/classes/com/wgcloud/common/ApplicationStartListener.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */